package cn.imvc.core;

import java.util.Iterator;
import java.util.Map.Entry;

import cn.imvc.data.domain.ViewRequest;

public class ModelUtil {
public static ViewRequest OrderByIdDesc(ViewRequest viewRequest){
	if(viewRequest==null){
		viewRequest=new ViewRequest();
		viewRequest.getSort().put("id", "desc");
	}else{
		Iterator<Entry<String, String>> it = viewRequest.getSort().entrySet().iterator();
		while(it.hasNext()){  
			Entry<String, String> entry=it.next();  
            if(entry.getValue().isEmpty()){  
                it.remove();
            }  
        }
		if(viewRequest.getSort().size()>1){
			if(viewRequest.getSort().containsKey("id")){
				viewRequest.getSort().remove("id");
			}
		}else if(viewRequest.getSort().size()==0){
			viewRequest.getSort().put("id", "desc");
		}
	}
	
	return viewRequest;
}
}
